package com.my.study.design.rule.support;

import com.my.study.design.rule.IRule;
import com.my.study.design.rule.RuleExecuteResult;

/**
 * 条件型规则
 *
 * @author: yidujun
 * @create: 2021/07/10 00:46
 */
public abstract class AbstractConditionRule<T> implements IRule {

    @Override
    public RuleExecuteResult execute(Object obj) {
        boolean judge = judge(convert(obj));
        return judge ? new RuleExecuteResult(RuleExecuteResult.EnumRuleResult.CONTINUE, obj)
                        : new RuleExecuteResult(RuleExecuteResult.EnumRuleResult.RETURN, obj);
    }

    /**
     * 转化类型
     *
     * @param obj
     * @return
     */
    public abstract T convert(Object obj);

    /**
     * 条件判断
     *
     * @param obj
     * @return
     */
    public abstract boolean judge(T obj);

}
